package cn.tedu.admin.mall.controller;

import cn.tedu.admin.mall.pojo.param.CategoryAddParam;
import cn.tedu.admin.mall.pojo.param.CategoryUpdateParam;
import cn.tedu.admin.mall.service.CategoryService;
import cn.tedu.tmall.common.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


//url 可以加版本号
//app 1.0   categories/list
//app 1.1  categories/list(arg)
//app 5.0  categories/list(arg,arg)
//app 强升
@Slf4j
@RequestMapping("/categories")
@RestController
@Api(tags = "类别管理")
@Validated
//todo 1 驗證框架不生效
//todo 2 接口文檔排序 不生效
//@Valid 提醒注意引入正確的包
public class CategoryController {

    //http://tea.mall/v1/category/list
    //http://tea.mall/category/add
    //http://tea.mall/category/info
    @Autowired
    private CategoryService contentService;

    @ApiOperation("3 类别列表")
    //@ApiOperationSupport(order = 200)
    //@RequestMapping(value = "list",method = RequestMethod.GET)
    @GetMapping("/category/list")
    public JsonResult listCategory(){
        //return contentService.listCategory();
        return JsonResult.ok();
    }
    //我们希望我们的所有controller 1 返回统一的格式 ,简化我们重复
    //如果正常支持的情况下,我们不想 CRUD create read update delete

    //@ApiOperationSupport(order = 100)
    @ApiOperation("1 添加类别")
    @PostMapping("/category/add")
    public JsonResult add(CategoryAddParam categoryAddParam){


        //打印日志的目的是为了出现问题好排查  问题 排查
        // 1都会出现什么问题?
        //    接口没找到
        //    插入的分类已经存在?
        //       1 前端的入参有问题
        //       2 我们的代码逻辑有问题;
        log.debug("开始处理添加分类请求,入参:{}",categoryAddParam);
        contentService.addCategory(categoryAddParam);
        JsonResult jsonResult = JsonResult.ok();
        log.debug("时间 处理添加分类请求完成,入参:{},出参:{}",categoryAddParam,jsonResult);
        //jsonResult.setState(200);
        // jsonResult.setMessage("");
        // jsonResult.ok();
        return jsonResult;

        //前端老哥 有点疏忽, if state == 200 ,保存失败
    }
    //@ApiOperationSupport(order = 300)
    @ApiOperation("2 查询类别")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "类别id",required = true,dataType = "Long")
    })
    @GetMapping("/category/get/{id}")
    //category/del/{id}
    //category/enable/{id} category/{id}/enable
    //category/{id}/get
    public JsonResult getCategoryById(@PathVariable Long id){
        return null;
    }

    //@ApiOperationSupport(order = 400)
    @ApiOperation("4 修改类别")
    @PostMapping("/category/update")
    public JsonResult updateCategory(CategoryUpdateParam categoryUpdateParam){
        return null;
    }

    //@ApiOperationSupport(order = 500)
    @ApiOperation("5 删除类别")
    @PostMapping("/category/del/{id}")
    public JsonResult Category(@PathVariable Long id){
        return null;
    }
}
